package com.example.caoben_back.config;

import com.example.caoben_back.contoller.AgentWebSocketHandler;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    private final ChatClient serviceChatClient;

    public WebSocketConfig(ChatClient serviceChatClient) {
        this.serviceChatClient = serviceChatClient;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new AgentWebSocketHandler(serviceChatClient), "/agent/service/ws")
                .setAllowedOrigins("*");
    }
}